package com.example.controller;


import com.example.pojo.Result;
import com.example.pojo.Student;
import com.example.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/students")
public class StudentController {
    @Autowired
    private StudentService studentService;
    //分页查询学生列表
    @GetMapping
    public Result findAll(@RequestParam(defaultValue = "1") Integer page,
                          @RequestParam(defaultValue = "5") Integer pageSize){
        return Result.success(studentService.findAll(page,pageSize));
    }
    //添加学生
    @PostMapping

    public Result save(@RequestBody Student student){
        studentService.save(student);
        return Result.success();
    }
    //删除学生
    @DeleteMapping("/{ids}")

    public Result delete(@PathVariable String ids){
        studentService.delete(ids);
        return Result.success();
    }
    //根据id查询学生
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        return Result.success(studentService.getById(id));
    }
    //修改学生
    @PutMapping

    public Result update(@RequestBody Student student){
        studentService.update(student);
        return Result.success();
    }
    //违纪扣分
    @PutMapping("/violation/{id}/{score}")

    public Result updateViolation(@PathVariable Integer id,@PathVariable Short score){
        studentService.updateViolation(id,score);
        return Result.success();
    }

}
